package com.zxkj.commonpatrol.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.base.BaseViewModel;
import com.czy.basecommon.utils.base.StateLiveData;
import com.zxkj.commonpatrol.model.entity.SelectProjectEntrity;
import com.zxkj.commonpatrol.model.response.ProjectDetailResponse;
import com.zxkj.commonpatrol.model.response.RouteSystemResponse;
import com.zxkj.commonpatrol.repoisity.AddCheckPointRepoisity;
import com.zxkj.commonpatrol.repoisity.ProblemListRepoisity;
import com.zxkj.commonpatrol.repoisity.ProjectListRepoisity;

import java.util.ArrayList;
import java.util.List;

public class ProjectListViewModel extends BaseViewModel<ProjectListRepoisity> {
    public StateLiveData<List<SelectProjectEntrity>> data=new StateLiveData<>();

    public StateLiveData<List<ProjectDetailResponse.Route>>DetailDatas=new StateLiveData<>();
    public StateLiveData<List<RouteSystemResponse.RouteSystemsBean>> Typedata=new StateLiveData<>();

    public ObservableField<String>a=new ObservableField<>("0");
    public ObservableField<String>b=new ObservableField<>("0");
    public ObservableField<String>c=new ObservableField<>("0");
    public ProjectListViewModel(@NonNull Application application) {
        super(application);
    }

    public  void  getDatas(int pageIndex,int PageSize,int type,String ProCode,String RouteTypeNo,String Filter ){
        mRepository.getSelectProject(pageIndex, PageSize, type, ProCode, RouteTypeNo, Filter, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                if (o!=null){
                    ProjectDetailResponse bean =(ProjectDetailResponse)o;
                    DetailDatas.postSuccess(bean.getRoutes());

                    a.set(bean.getProRouteStatisInfo().Pending+"");
                    b.set(bean.getProRouteStatisInfo().Completed+"");
                    c.set(bean.getProRouteStatisInfo().All+"");

                }
            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {
                DetailDatas.postFailure((Integer)o,(String)t1);
            }
        });
    }
    public void  getSelectData(int type){

//        mRepository.getSelectProject(type,new BaseRepository.MyBaseDataCallBack() {
//            @Override
//            public void onDataSuccessCallBack(Object o) {
//                List<SelectProjectEntrity> da=(List<SelectProjectEntrity>)o;
//                data.postSuccess(da);
//            }
//
//            @Override
//            public void onDataFailCallBack(Object o, Object t1) {
//
//            }
//        });
    }


    public void  getTypeData(){
        mRepository.getRouteSystems(new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                if (o!=null){
                    RouteSystemResponse routeSystemResponse =(RouteSystemResponse)o;
                    List<RouteSystemResponse.RouteSystemsBean> data = routeSystemResponse.getRouteSystems();
                    if (data==null){
                        data=new ArrayList<>();
                    }
                    Typedata.postSuccess(data);
                }
            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {
                Typedata.postFailure((Integer)o,(String)t1);
            }
        });
    }

}
